package 线程;

import java.security.PublicKey;

public class Pay implements Runnable {
    public static int num=0;//人
    public  static int count=1000;//米
    public static boolean fiag=false;//
    public synchronized void sale(){
        if (count<=0){
            fiag=true;
            return;
        }
        num++;
        count--;
        System.out.println(Thread.currentThread().getName()+"买到了第"+num+"张票剩余"+count+"张票");
    }
    public void run(){
        while (true){
            synchronized (this){
                if (count<=0){
                    break;
                }
            }
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            sale();
        }
    }
}
